#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int N=2600;
const int INF=0x3f3f3f3f;
int t,c,ts,te;

int dp[N];
int vis[N];
vector<pair<int,int>> edge[N];
struct cmp{
	bool operator()(pair<int,int>& p1,pair<int,int>& p2)
	{
		if(p1.second==p2.second)
			return p1.first>p2.first;
		return p1.second>p2.second;
	}
};
void dijkstra(int x)
{
	for(int i=1;i<=t;i++)
		dp[i]=INF;
	dp[x]=0;
	priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
	q.push({x,0});
	while(q.size())
	{
		int u=q.top().first;
		vis[u]=1;
		q.pop();
		for(auto& e:edge[u])
		{
			if(vis[e.first])
				continue;
		
			if(dp[e.first]>dp[u]+e.second)
			{
				dp[e.first]=dp[u]+e.second;
				q.push({e.first,dp[e.first]});
			}
			
		}
	}
}
int main()
{
	cin>>t>>c>>ts>>te;
	
	for(int i=0;i<c;i++)
	{
		int rs,re,c;
		cin>>rs>>re>>c;
		edge[rs].push_back({re,c});
		edge[re].push_back({rs,c});
	}
	
	dijkstra(ts);
	
	
	cout<<dp[te]<<endl;
	
	
	return 0;
}
